package cn.personal.study.springbootdemo.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.personal.study.springbootdemo.service.StudentScoreService;
import cn.personal.study.springbootdemo.service.StudentService;

/**
 * bean 配置类
 */
@Configuration
public class StudentConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public StudentService studentService() {
        return new StudentService();
    }

    @Bean
    @ConditionalOnProperty(prefix = "study", name = "test", matchIfMissing = true, havingValue = "a")
    public StudentScoreService studentScoreServiceA(StudentService studentService) {
        return new StudentScoreService(studentService);
    }

    @Bean
    @ConditionalOnProperty(prefix = "study", name = "test", havingValue = "b")
    public StudentScoreService studentScoreServiceB() {
        return new StudentScoreService();
    }

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper();
    }
}
